<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>浅拷贝</title>
</head>

<body>
  <script>
    // 浅拷贝只是拷贝一层, 更深层次对象级别的只拷贝引用.
    var obj = {
      uname: 'zs',
      age: 18,
      hobby: ['抽烟', '喝酒', '烫头'],
    }
    var o = {};
    // for (var k in obj) {
    //   o[k] = obj[k];
    // }
    // o.uname = 'ls';
    // console.log(o); //{uname: "ls", age: 18, hobby: Array(3)}
    // console.log(obj); //{uname: "zs", age: 18, hobby: Array(3)}

    // // 浅拷贝对于复杂数据类型 拷贝的是地址
    // o.hobby.push('玩')
    // console.log(o);   //{uname: "ls", age: 18, hobby: Array(4)}
    // console.log(obj)  //{uname: "zs", age: 18, hobby: Array(4)}给o添加了hobby，obj也会跟着变化

    // --------------------浅拷贝语法糖--------------------
    Object.assign(o, obj);
    console.log(o);
  </script>
</body>

</html>